home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / man / man-part1 / cat1 / sprintf.1 < prev    next >
Text File  |  1999-09-16  |  11KB  |  265 lines

  1.  
  2.  
  3.  
  4. printf(1)                      Scilab Function                      printf(1)
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. NAME
  12.   printf,fprintf,sprintf - Emulator of C language printf functions
  13.  
  14. CALLING SEQUENCE
  15.   printf(format,value_1,..,value_n)
  16.   fprintf(file,format,value_1,..,value_n)
  17.   str=sprintf(format,value_1,..,value_n)
  18.  
  19. PARAMETERS
  20.  
  21.   format    : a Scilab string. Specifies a character string combining literal
  22.             characters with conversion specifications.
  23.  
  24.   value_i   : Specifies the data to be converted according to the format
  25.             parameter.
  26.  
  27.   str       : column vector of character strings
  28.  
  29.   file      : a Scilab string specifying a file name or a logical unit number
  30.             (see file)
  31.  
  32. DESCRIPTION
  33.   The printf function converts, formats, and writes its value parameters,
  34.   under control of the format parameter, to the standard output.
  35.  
  36.   The fprintf function converts, formats, and writes its value parameters,
  37.   under control of the format parameter, to the file specified by its file
  38.   parameter.
  39.  
  40.   The sprintf function converts, formats, and stores its value parameters,
  41.   under control of the format parameter.
  42.  
  43.   The format parameter is a character string that contains two types of
  44.   objects:
  45.  
  46.   Literal characters
  47.             : which are copied to the output stream.
  48.  
  49.   Conversion specifications
  50.             : each of which causes zero or more items to be fetched from the
  51.             value parameter list.
  52.  
  53.   If there are not enough items for format in the value parameter list,
  54.   sprintf generate an error.  If any values remain after the entire format
  55.   has been processed, they are ignored.
  56.  
  57.   Conversion Specifications
  58.  
  59.   Each conversion specification in the format parameter has the following
  60.   syntax:
  61.  
  62.  
  63.   -         A % (percent) sign.
  64.  
  65.   -         Zero or more options, which modify the meaning of the conversion
  66.             specification.  The following list contains the option characters
  67.             and their meanings:
  68.  
  69.             -       : Left align, within the field, the result of the conver-
  70.                     sion.
  71.  
  72.             +       : Begin the result of a signed conversion with a sign (+
  73.                     or -).
  74.  
  75.             "space" : Prefix a space character to the result if the first
  76.                     character of a signed conversion is not a sign.  If both
  77.                     the (space) and + options appear, the (space) option is
  78.                     ignored.
  79.  
  80.             #       : Convert the value to an alternate form.  For c, d, i,
  81.                     s, and u conversions, the # option has no effect.  For o
  82.                     conversion, # increases the precision to force the first
  83.                     digit of the result to be a 0 (zero).  For x and X
  84.                     conversions, a nonzero result has 0x or 0X prefixed to
  85.                     it.  For e, E, f, g, and G conversions, the result always
  86.                     contains a decimal point, even if no digits follow it.
  87.                     For g and G conversions, trailing zeros are not removed
  88.                     from the result.
  89.  
  90.             0       : Pad to the field width, using leading zeros (following
  91.                     any indication of sign or base) for d, i, o, u, x, X, e,
  92.                     E, f, g, and G conversions; no space padding is per-
  93.                     formed.  If the 0 and - (dash) flags both appear, the 0
  94.                     flag is ignored.  For d, i, o u, x, and X conversions, if
  95.                     a precision is specified, the 0 flag is also ignored.
  96.  
  97.   An optional decimal digit string that specifies the minimum field width.
  98.   If the converted value has fewer characters than the field width, the field
  99.   is padded on the left to the length specified by the field width.  If the
  100.   left-adjustment option is specified, the field is padded on the right.
  101.  
  102.   An optional precision.  The precision is a . (dot) followed by a decimal
  103.   digit string.  If no precision is given, the parameter is treated as 0
  104.   (zero).  The precision specifies:
  105.  
  106.        - The minimum number of digits to appear for d, u, o, x, or X conver-
  107.          sions
  108.  
  109.        - The number of digits to appear after the decimal point for e, E, and
  110.          f conversions
  111.  
  112.        - The maximum number of significant digits for g and G conversions
  113.  
  114.        - The maximum number of characters to be printed from a string in an s
  115.          conversion
  116.  
  117.   -    A character that indicates the type of conversion to be applied:
  118.  
  119.        %     : Performs no conversion.  Displays %.
  120.  
  121.        d,i   :Accepts an integer value and converts it to signed decimal
  122.              notation.  The precision specifies the minimum number of digits
  123.              to appear.  If the value being converted can be represented in
  124.              fewer digits, it is expanded with leading zeros.  The default
  125.              precision is 1.  The result of converting a zero value with a
  126.              precision of zero is a null string.  Specifying a field width
  127.              with a zero as a leading character causes the field width value
  128.              to be padded with leading zeros.
  129.  
  130.        u     :Accepts an integer value and converts it to unsigned decimal
  131.              notation.  The precision specifies the minimum number of digits
  132.              to appear.  If the value being converted can be represented in
  133.              fewer digits, it is expanded with leading zeros.  The default
  134.              precision is 1.  The result of converting a zero value with a
  135.              precision of zero is a null string.  Specifying a field width
  136.              with a zero as the leading character causes the field width
  137.              value to be padded with leading zeros.
  138.  
  139.        o     :Accepts an integer value and converts it to unsigned octal
  140.              notation.  The precision specifies the minimum number of digits
  141.              to appear.  If the value being converted can be represented in
  142.              fewer digits, it is expanded with leading zeros.  The default
  143.              precision is 1.  The result of converting a zero value with a
  144.              precision of zero is a null string.  Specifying a field width
  145.              with a zero as the leading character causes the field width
  146.              value to be padded with leading zeros.  An octal value for field
  147.              width is not implied.
  148.  
  149.        x, X  :Accepts an integer value and converts it to unsigned hexade-
  150.              cimal notation.  The letters ``abcdef'' are used for the x
  151.              conversion; the letters ``ABCDEF'' are used for the X conver-
  152.              sion.  The precision specifies the minimum number of digits to
  153.              appear.  If the value being converted can be represented in
  154.              fewer digits, it is expanded with leading zeros.  The default
  155.              precision is 1.  The result of converting a zero value with a
  156.              precision of zero is a null string.  Specifying a field width
  157.              with a zero as the leading character causes the field width
  158.              value to be padded with leading zeros.
  159.  
  160.        f     : Accepts a float or double value and converts it to decimal
  161.              notation in the format %[-]ddd.ddd.  The number of digits after
  162.              the decimal point is equal to the precision specification.
  163.  
  164.              - If no precision is specified, six digits are output.
  165.  
  166.              - If the precision is zero, no decimal point appears and the
  167.                system outputs a number rounded to the integer nearest to
  168.                value.
  169.  
  170.              - If a decimal point is output, at least one digit is output
  171.                before it.
  172.  
  173.        e, E  :Accepts a real  and converts it to the exponential form
  174.              %[-]d.ddde+/-dd.  There is one digit before the decimal point,
  175.              and the number of digits after the decimal point is equal to the
  176.              precision specification.
  177.  
  178.              -                             If no precision is specified, ,
  179.                                            six digits are output.
  180.  
  181.              -                             If the precision is zero, , no
  182.                                            decimal point appears.
  183.  
  184.              -                             The E conversion character pro-
  185.                                            duces a number with E instead of e
  186.                                            before the exponent.  The exponent
  187.                                            always contains at least two
  188.                                            digits.  If the value is zero, the
  189.                                            exponent is zero.
  190.  
  191.        g, G  : Accepts a real  and converts it in the style of the e, E, or f
  192.              conversion characters, with the precision specifying the number
  193.              of significant digits.  Trailing zeros are removed from the
  194.              result.  A decimal point appears only if it is followed by a
  195.              digit.  The style used depends on the value converted.  Style e
  196.              (E, if G is the flag used) results only if the exponent result-
  197.              ing from the conversion is less than -4, or if it is greater or
  198.              equal to the precision.
  199.  
  200.        c     :Accepts and displays an integer value converted to a character.
  201.  
  202.        s     :Accepts a string value  and displays characters from the string
  203.              to the end or the number of characters indicated by the preci-
  204.              sion is reached.  If no precision is specified, all characters
  205.              up to the end are displayed.
  206.   A field width or precision can be indicated by an * (asterisk) instead of a
  207.   digit string.  In this case, an integer value parameter supplies the field
  208.   width or precision.  The value parameter converted for output is not
  209.   fetched until the conversion letter is reached, so the parameters specify-
  210.   ing field width or precision must appear before the value to be converted
  211.   (if any).
  212.  
  213.   If the result of a conversion is wider than the field width, the field is
  214.   expanded to contain the converted result.
  215.  
  216.   The representation of the plus sign depends on whether the + or (space)
  217.   formatting option is specified.
  218.  
  219. EXAMPLES
  220.   fahr=120
  221.   sprintf('%3d Fahrenheit = %6.1f Celsius',fahr,(5/9)*(fahr-32))
  222.  
  223.   printf('Result is:0lpha=%f",0.535)
  224.  
  225.   u=file('open','results','unknown') //open the result file
  226.   t=0:0.1:2*%pi;
  227.   for tk=t
  228.    fprintf(u,'time = %6.3f value = %6.3f',tk,sin(tk)) // write a line
  229.   end
  230.   file('close',u) //close the result file
  231.  
  232. SEE ALSO
  233.   string, print, write, format, disp, file
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.